package com.example.demo.day0302;

import java.lang.reflect.Constructor;

public class Test {
    public static void main(String[] args) {
        Class clazz = Student.class;//获取class实例
//            Class clazz = Class.forName("com.example.demo.day0302.Student");

        Class superc = clazz.getSuperclass();//获取父类
        System.out.println(superc.getName());

        Class[] interfaces = clazz.getInterfaces();//获取当前类的所有接口,是以数组的形式得到的
        for (Class c : interfaces) {
            System.out.println(c.getName());
        }

        Constructor[] con = clazz.getConstructors();//获取到公共的构造方法
        for (Constructor constructor : con){
            System.out.println(constructor.getName()+" "+constructor.getModifiers());
            Class[] parmclazz = constructor.getParameterTypes();//获取构造方法的参数类型,有几个参数数组的元素就有几个
            for (Class pc : parmclazz ){
                System.out.println(constructor.getName() +" "+ pc.getName());
            }
        }
        System.out.println("-----------------------");
        Constructor[] con1 = clazz.getDeclaredConstructors();//获取到所有的构造方法
        for (Constructor constructor1 : con1){

            System.out.println(constructor1.getName()+" "+constructor1.getModifiers());
            Class[] parmclazz1 = constructor1.getParameterTypes();//获取构造方法的参数类型,有几个参数数组的元素就有几个
            for (Class pc1 : parmclazz1 ){
                System.out.println(pc1.getName() +" "+ constructor1.getName());
            }
            System.out.println("---------------------");
        }
    }
}
